package com.sykj.qianxuezhan.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.sykj.qianxuezhan.bean.NurseProject;
import com.sykj.qianxuezhan.bean.NurseType;
import com.sykj.qianxuezhan.server.NursePeojectService;
import com.sykj.qianxuezhan.server.NurseTypeService;
import com.sykj.util.reponse.CommonEnum;
import com.sykj.util.reponse.ResultBody;
import org.springframework.beans.factory.annotation.Autowired;;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author QianXuezhan
 * @Date 2020/7/20 8:11
 * @Description: TODO
 */
@CrossOrigin
@RestController
@RequestMapping("/nurseProject")
public class NurseProjectController {
    @Autowired
    private NursePeojectService nursePeojectService;
    @Autowired
    private  NurseTypeService nurseTypeService;

    /**
    * @Description:  查询所有综合查询
    **/
    @RequestMapping(value="/queryNurseProject",method = RequestMethod.GET)
    public  List<NurseProject>  queryNurseProject(String  projectId,String  projectName,String  typeId,String status){
        NurseProject  nurseProject=new NurseProject();
        nurseProject.setProjectId(projectId);
        nurseProject.setProjectName(projectName);
        nurseProject.setTypeId(typeId);
        nurseProject.setStatus(status);
        return  nursePeojectService.queryNurseProject(nurseProject);
    }
    /**
    * @Description:  查询项目类型
    **/
    @RequestMapping(value="/queryNurseType",method = RequestMethod.GET)
    public Map  queryNurseType(){
        Map map = new HashMap();
        List<NurseType> nurseTypes= nurseTypeService.list();
        System.out.println(nurseTypes);
        map.put("nurseTypes",nurseTypes);
        return  map;
    }

    /**
    * @Description:  修改项目状态做假删除
    **/
    @RequestMapping("/updateNurseTypeIdDel")
    public ResultBody  updateNurseTypeIdDel(String  projectId){
        UpdateWrapper  updateWrapper=new UpdateWrapper();
        updateWrapper.set("is_del",'1');
        updateWrapper.eq("project_id",projectId);
        nursePeojectService.update(updateWrapper);
        return   new ResultBody(CommonEnum.SUCCESS);
    }
    /**
    * @Description:  添加护理项目信息
    **/
    @RequestMapping("/addNureseProject")
    public  ResultBody  addNureseProject(NurseProject nurseProject){
        //根据定时器生成id
        String projectId=Long.toString(System.currentTimeMillis());
        nurseProject.setProjectId(projectId);
        nurseProject.setIsDel("0");
        nursePeojectService.addNurseProject(nurseProject);
        return new ResultBody(CommonEnum.SUCCESS);
    }

    /**
     * @Description:  添加护理项目信息
     **/
    @RequestMapping("/updateNureseProject")
    public  ResultBody  updateNureseProject(NurseProject nurseProject){
        UpdateWrapper  updateWrapper=new UpdateWrapper();
        updateWrapper.set("project_name",nurseProject.getProjectName());
        updateWrapper.set("type_id",nurseProject.getTypeId());
        updateWrapper.set("server_time",nurseProject.getServerTime());
        updateWrapper.set("rmb_price",nurseProject.getRmbPrice());
        updateWrapper.set("beauty_price",nurseProject.getBeautyPrice());
        updateWrapper.set("manual_price",nurseProject.getManualPrice());
        updateWrapper.set("active_price",nurseProject.getActivePrice());
        updateWrapper.set("sort_no",nurseProject.getSortNo());
        updateWrapper.set("status",nurseProject.getStatus());
        updateWrapper.eq("project_id",nurseProject.getProjectId());
        nursePeojectService.update(updateWrapper);
        return   new ResultBody(CommonEnum.SUCCESS);

    }
    }


